const api = require('../../utils/interface.js')
Page({
  data: {
    userInfo: {},
    state: false, //用户类型判断
    src: "",
    carState:-1,
    carText:"",
    color:""
  },
  //领券中心
  gocoupon() {
    if (!this.data.userInfo.phone) {
      wx.redirectTo({
        url: '/pages/login/login?page=pages/person/person',
      })
      return false
    }
    wx.navigateTo({
      url: '/pages/couponcenter/couponcenter'
    })
  },
  //优惠卡券
  couponcard() {
    if (!this.data.userInfo.phone) {
      wx.redirectTo({
        url: '/pages/login/login?page=pages/person/person',
      })
      return false
    }
    wx.navigateTo({
      url: '/pages/couponcard/couponcard'
    })
  },
  //设置
  goset() {
    wx.navigateTo({
      url: '/pages/userset/userset'
    })
  },
  //我的订单
  orderList() {
    console.log(this.data.userInfo.phone)
    if (!this.data.userInfo.phone) {
      wx.redirectTo({
        url: '/pages/login/login?page=pages/person/person',
      })
      return false
    }
    wx.navigateTo({
      url: '/pages/myorder/maorder',
    })
  },
  //更多
  gomore() {
    wx.navigateTo({
      url: '/pages/showstatus/showstatus',
    })
  },
  //车生活
  goshopping() {
    if (!this.data.userInfo.phone) {
      wx.redirectTo({
        url: '/pages/login/login?page=pages/person/person',
      })
      return false
    }
    wx.navigateTo({
      url: '/pages/cardlife/cardlife',
    })
  },
  //商务合作
  goshop() {
    wx.navigateTo({
      url: '/pages/showstatus/showstatus',
    })
  },
  //会员中心
  gomember() {
    if (!this.data.userInfo.phone) {
      wx.redirectTo({
        url: '/pages/login/login?page=pages/person/person',
      })
      return false
    }
    wx.navigateTo({
      url: '/pages/showstatus/showstatus',
    })
  },
  //服务卡
  serve() {
    if (!this.data.userInfo.phone) {
      wx.redirectTo({
        url: '/pages/login/login?page=pages/person/person',
      })
      return false
    }
    wx.navigateTo({
      url: '/pages/servecard/servecard',
    })
  },
  //消息中心
  onclick() {
    wx.navigateTo({
      url: '/pages/person/message/message',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function(options) {
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: "#ffffff"
    })
    this.getUserinfo()
  },
  // 获取用户头像昵称
  getUserinfo(e) {
    let user = wx.getStorageSync('userInfo')
    if (!user){
      this.setData({
        userInfo:{},
        src:"",
      })
      return false
    }
    api.getMemberInfo({
      id: user.id
    }).then(res => {
      console.log(res.data)
      this.data.userInfo = res.data.result
      let src = ""
      // if (this.data.userInfo.memberCarInfoDTO){
        
      //   switch (this.data.userInfo.memberCarInfoDTO.approvalStatus){
      //     case "0":
      //       this.data.carState = '0'
      //       this.data.carText = "认证审核中"
      //     break;
      //     case "1":
      //       this.data.carState = '1'
      //       let nowDate = new Date().getTime()
      //       if (nowDate >= this.data.userInfo.memberCarInfoDTO.expireTime){
      //         this.data.carText = "认证已过期，请重新提交"
      //         this.data.carState = '2'
      //       }else{
      //         switch (this.data.userInfo.memberCarInfoDTO.certificationType) {
      //           case '1':
      //             src = "/static/shangyongche.png"
      //             break;
      //           case '2':
      //             src = "/static/wyc.png"
      //             break;
      //           case '3':
      //             src = "/static/czc.png"
      //             break;
      //           case '4':
      //             src = "/static/sic.png"
      //             break;
      //         }
      //       }
      //     break;
      //     case "2":
      //       this.data.carState = '2'
      //       this.data.carText = "审核未通过,请重新认证"
      //   }
      //   this.setData({
      //     src: src,
      //     carState: this.data.carState,
      //     carText: this.data.carText
      //   })
      // }
      
    })
  },
  goHelp() {
    wx.navigateTo({
      url: '/pages/helpCenter/helpCenter',
    })
  },
  goShen(){
    if (this.data.carState == '2'){
      this.cartAuth()
    }
  },
  // 车辆认证
  cartAuth() {
    if (!this.data.userInfo.phone) {
      wx.redirectTo({
        url: '/pages/login/login?page=pages/person/person',
      })
      return false
    }
    if (this.data.userInfo.memberCarInfoDTO&&this.data.userInfo.memberCarInfoDTO.approvalStatus == 0) {
      wx.showModal({
        title: '提示',
        content: '您已提交资料，请等待审核',
        showCancel:false
      })
      return false
    }
    wx.navigateTo({
      url: '/pages/cardlife/cardlife',

    })
    // wx.navigateTo({
    //   url: '/pages/netWorkCar/netWorlCar',
    // })
  },
  onLoad(){

  }
})